<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:zj="http://www.zju.edu.cn" exclude-result-prefixes="zj">
  <xsl:import href="../Tk2Base/Button.xslt"/>
  <xsl:import href="../Tk2Base/EditItems.xslt"/>
  <xsl:import href="TableFrame.xslt"/>
  <xsl:param name="Doc"/>
  <xsl:param name="IsPost"/>
  <xsl:variable name="zj:Toolkit" select="/Toolkit"/>
  <xsl:variable name="zj:XmlData" select="$Doc"/>
  <xsl:template name="zj:Content">
    <xsl:call-template name="zj:PostScript"/>
    <xsl:apply-templates select="$zj:XmlData/Toolkit/zj:Table" mode="zj:Display"/>
  </xsl:template>
  <xsl:template name="zj:PostScript">
    <xsl:param name="Tables"/>
    <script language="JavaScript">
      function Post2(webFile, dataSet, save)
      {
        var retURL = "<xsl:value-of select="$zj:DRetURL"/>";
        var tableNames = "<xsl:value-of select="$zj:XmlData/Toolkit/@Tables"/>";
        var fieldNames = "<xsl:value-of select="$zj:XmlData/Toolkit/@Fields"/>";
        if (retURL != "" &amp;&amp; save == "Save")
          webFile += "&amp;RetURL=" + retURL;
        PostData(tableNames, fieldNames, webFile, dataSet, save);
      }
      <xsl:value-of select="$zj:XmlData/Toolkit/zj:RefJS"/>
    </script>
  </xsl:template>
  <xsl:template match="zj:Table" mode="zj:Display">
    <table width="100%" border="0" cellpadding="2" cellspacing="0" class="tb-list" id="{@TableName}">
      <xsl:variable name="Data" select="$zj:Toolkit/*[local-name()=current()/@TableName]"/>
      <xsl:choose>
        <xsl:when test="@Style='Normal'">
          <xsl:call-template name="zj:NormalDisplay">
            <xsl:with-param name="Data" select="$Data"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="@Style='Table'">
          <xsl:call-template name="zj:TableDisplay">
            <xsl:with-param name="Data" select="$Data"/>
            <xsl:with-param name="Fix" select="false()"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test="@Style='FixTable'">
          <xsl:call-template name="zj:TableDisplay">
            <xsl:with-param name="Data" select="$Data"/>
            <xsl:with-param name="Fix" select="true()"/>
          </xsl:call-template>
        </xsl:when>
      </xsl:choose>
    </table>
  </xsl:template>
  <xsl:template name="zj:TableHead">
    <xsl:param name="TableNode"/>
    <xsl:if test="$TableNode/@TableDesc != ''">
      <tr>
        <th width="100%">
          <div align="left">
            <xsl:value-of select="$TableNode/@TableDesc"/>
          </div>
        </th>
        <th align="right" class="cur-hand" onclick="showContentList('{$TableNode/@TableName}');">
          <img src="../images/ico_listup.gif" id="imgContentList{$TableNode/@TableName}" border="0" align="right">
            <xsl:if test="$TableNode/@Expand='false'">
              <xsl:attribute name="src">../images/ico_listdown.gif</xsl:attribute>
            </xsl:if>
          </img>
        </th>
      </tr>
    </xsl:if>
  </xsl:template>
  <xsl:template name="zj:NormalDisplay">
    <xsl:param name="Data"/>
    <xsl:variable name="current" select="."/>
    <xsl:call-template name="zj:TableHead">
      <xsl:with-param name="TableNode" select="."/>
    </xsl:call-template>
    <tr>
      <td colspan="2" class="td-bg" id="divContentList{@TableName}">
        <xsl:if test="@Expand='false'">
          <xsl:attribute name="style">display: none</xsl:attribute>
        </xsl:if>
        <xsl:for-each select="$Data">
          <table width="100%" border="0" cellspacing="1" cellpadding="1">
            <xsl:apply-templates select="$current/Hidden/zj:Field" mode="zj:Item">
              <xsl:with-param name="DataRecord" select="."/>
            </xsl:apply-templates>
            <xsl:apply-templates select="$current/Row" mode="zj:TableRow">
              <xsl:with-param name="DataRecord" select="."/>
              <xsl:with-param name="Pos" select="position()"/>
            </xsl:apply-templates>
          </table>
        </xsl:for-each>
      </td>
    </tr>
  </xsl:template>
  <xsl:template match="Row" mode="zj:TableRow">
    <xsl:param name="DataRecord"/>
    <xsl:param name="Pos"/>
    <tr>
      <xsl:apply-templates select="zj:Field" mode="zj:Item">
        <xsl:with-param name="DataRecord" select="$DataRecord"/>
        <xsl:with-param name="Pos" select="$Pos"/>
      </xsl:apply-templates>
    </tr>
  </xsl:template>
  <xsl:template match="zj:Field" mode="zj:Item">
    <xsl:param name="DataRecord"/>
    <xsl:param name="Pos" select="1"/>
    <xsl:variable name="HtmlCtrl" select="zj:HtmlCtrl/@HtmlCtrl"/>
    <xsl:variable name="Value" select="$DataRecord/*[local-name()=current()/zj:FieldName]"/>
    <xsl:if test="@IsKey = 'true'">
      <xsl:call-template name="zj:HiddenKey">
        <xsl:with-param name="Field" select="."/>
        <xsl:with-param name="Value" select="$Value"/>
      </xsl:call-template>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="$HtmlCtrl='Hidden'">
        <xsl:call-template name="zj:Hidden">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='Detail'">
        <xsl:call-template name="zj:Detail">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='DetailHidden'">
        <xsl:call-template name="zj:DetailHidden">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='DetailMultiSelect'">
        <xsl:call-template name="zj:DetailMultiSelect">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='DetailUpload'">
        <xsl:call-template name="zj:DetailUpload">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="DataRecord" select="$DataRecord"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='DetailHTML'">
        <xsl:call-template name="zj:DetailHTML">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='DetailTextArea'">
        <xsl:call-template name="zj:DetailTextArea">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='Text' or $HtmlCtrl = 'CheckBox' or $HtmlCtrl='File' or $HtmlCtrl='Password'">
        <xsl:call-template name="zj:Input">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
          <xsl:with-param name="HtmlCtrl" select="$HtmlCtrl"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='Combo'">
        <xsl:call-template name="zj:Combo">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='TextArea'">
        <xsl:call-template name="zj:TextArea">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='Radio'">
        <xsl:call-template name="zj:Radio">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='EasySearch'">
        <xsl:call-template name="zj:EasySearch">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='CheckBoxList'">
        <xsl:call-template name="zj:CheckListGroup">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='MultiSelect'">
        <xsl:call-template name="zj:MultiSelect">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='Upload'">
        <xsl:call-template name="zj:Upload">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
          <xsl:with-param name="Pos" select="$Pos"/>
          <xsl:with-param name="DataRecord" select="$DataRecord"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:when test="$HtmlCtrl='HTML'">
        <xsl:call-template name="zj:HTML">
          <xsl:with-param name="Field" select="."/>
          <xsl:with-param name="Value" select="$Value"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
